package biz.ezcom.design.pattern.interpreter;

public class Client {
	public static void main(String[] args) {
		Context context = new Context();
		String playText = "T 500 O 2 E 0.5 G 0.5 A 3 E 0.5 G 0.5 D 3 E 0.5 G 0.5 A 0.5 O 3 C 1 O 2 A 0.5 G 1 C 0.5 E 0.5 D 3 ";
		context.setPlayText(playText);
		
		AbstractExpression expression = null;
		while(context.getPlayText().length() > 0) {
			String text = context.getPlayText().substring(0,1);
			//此处可用工厂
			if(text.equals("O")){
				expression = new ScaleExpression();
			}else if(text.equals("A") 
					|| text.equals("B") 
					|| text.equals("C") 
					|| text.equals("D") 
					|| text.equals("E") 
					|| text.equals("F") 
					|| text.equals("G")){
				expression = new NoteExpression();
			}else if(text.equals("T")){
				expression = new SpeedExpression();
			}
			
			expression.interpret(context);
		}
		
	}
}
